home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / parse / _scanner.pyc (.txt) < prev   
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  47 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import sre_parse
  5. import sre_compile
  6. from sre_constants import BRANCH, SUBPATTERN
  7.  
  8. class Scanner(object):
  9.     
  10.     def __init__(self, lexicon, flags = 0):
  11.         self._Scanner__lexicon = lexicon
  12.         p = []
  13.         s = sre_parse.Pattern()
  14.         s.flags = flags
  15.         for phrase, action in lexicon:
  16.             p.append(sre_parse.SubPattern(s, [
  17.                 (SUBPATTERN, (len(p) + 1, sre_parse.parse(phrase, flags)))]))
  18.         
  19.         s.groups = len(p) + 1
  20.         p = sre_parse.SubPattern(s, [
  21.             (BRANCH, (None, p))])
  22.         self._Scanner__scaner = sre_compile.compile(p)
  23.  
  24.     
  25.     def scan(self, string):
  26.         result = []
  27.         append = result.append
  28.         match = self._Scanner__scaner.scanner(string).match
  29.         i = 0
  30.         while True:
  31.             m = match()
  32.             if not m:
  33.                 break
  34.             j = m.end()
  35.             if i == j:
  36.                 break
  37.             action = self._Scanner__lexicon[m.lastindex - 1][1]
  38.             if callable(action):
  39.                 self.match = m
  40.                 action = action(self, m.group())
  41.             if action is not None:
  42.                 append(action)
  43.             i = j
  44.         return (result, string[i:])
  45.  
  46.  
  47.